import request from "./request.js"
import {
	app_name
} from "./open_from.js"
//openid登录
// export const LoginApi = (data) => request("auth/openid2Token", data);
// 登录
export const LoginApi = (data) => request("auth/code2Session", data);
// 刷新token TokenShuaApi
export const TokenShuaApi = (data) => request("auth/refreshToken", data);
// 首页(...)
export const GetHomeListApi = (params) => request("homePage/chart", params);
// 用户信息
export const UserApi = (data) => request("user/info", data);
/**=====================================收藏====================================**/
//列表
export function getFavoriteList(data) {
	return request('user/favorite/list', {
		method: 'GET',
		data
	})
}

//删除追剧列表
export function getFavoriteDelete(data) {
	return request('user/favorite/delete', {
		method: 'DELETE',
		data
	})
}

//添加追剧列表
export function getEpisodeAdd(data) {
	return request('user/favorite/add', {
		method: 'POST',
		data
	})
}

/**=====================================详情=====================================**/


// 内部drama_id-抖音id 互查
export function getOriginId(data) {
	return request('tiktok/drama/origin', {
		method: 'GET',
		data
	})
}

// 剧目详情
export function getDramaDetail(data) {
	return request('drama/detail', {
		method: 'GET',
		data
	})
}

//剧集详情
export function getEpisodeShow(data) {
	return request('episode/watch', {
		method: 'GET',
		data
	})
}

//剧集目录
export function getEpisodeCatalogue(data) {
	return request('episode/catalogue', {
		method: 'GET',
		data,
		showLoading: false
	})
}

// 猜你喜欢
export function getGuessYouLikes(data) {
	return request('homePage/drama/guessYouLikes', {
		method: 'GET',
		data
	})
}
/**=====================================首页=====================================**/


// 推荐位-查看更多
export function getLookMore(data) {
	return request('homePage/chart/pageList', {
		method: 'GET',
		data
	})
}
// 首页分类数据
export function getRankList(data) {
	return request('homePage/ranks', {
		method: 'GET',
		data
	})
}

/**=====================================充值=====================================**/
// 充值模板
export function getConfigRecharges(data) {
	return request('config/recharges', {
		method: 'GET',
		data
	})
}

// 充值记录
export function getUserBillingList(data) {
	return request('userBilling/list', {
		method: 'GET',
		data
	})
}

/**=====================================观看历史=====================================**/
// 历史列表
export function getUserWatchRecordList(data) {
	return request('user/watchHistory/list', {
		method: 'GET',
		data
	})
}

//删除观看历史
export function getUserWatchRecordDelete(data) {
	return request('user/watchHistory/delete', {
		method: 'DELETE',
		data
	})
}

//保存观看历史
export function getUserWatchRecordAdd(data) {
	return request('user/watchHistory/add', {
		method: 'POST',
		data
	})
}

// 搜索
export const SearchApi = (params) => request("book/library", params);
// 阅读历史
export const ReadHistoyApi = (params) => request("userRead/list", params);
// 书架列表
export const BookcaseApi = (params) => request("bookcase/list", params);
// 加入书架
export const AddbooksApi = (params) => request("bookcase/store", params);
// 删除书架
export const delbooksApi = (data) => request("bookcase/destroy", data);
// 充值金额配置
export const MemberApi = (params) => request("config/douyinMiniRecharge", params);
// 充值记录
export const RechargeRecordApi = (params) => request("userRecharge/list", params);
// 充值
export const RechargeApi = (data) => request("pay/new_pay", data);
// 删除阅读历史
export const DelHistoryApi = (params) => request("userRead/destroy", params);
// 保存阅读记录
export const SaveHistoryApi = (params) => request("userRead/store", params);
// 相似推荐
export const XiangSilApi = (params) => request("chart/similarRecommend", params);
// 书籍详情
export const IntroductionApi = (data) => request("book/brevitydetail", data);
// 书籍口令
export const SharecommandApi = (data) => request("users/bookPassword", data);
// 填写邀请码
export const CodeApi = (data) => request("distribution/fillInviteCode", data);
// 账户余额
export const UserBalanceApi = (data) => request("distribution/userBalance", data);
// 今日收益
export const TodayearningsApi = (params) => request("distribution/userIncomeToday", params);
// 历史收益
export const HistoryearningsApi = (data) => request("distribution/userIncomeHistory", data);
// 提现记录
export const TixianjiluApi = (data) => request("distribution/userWithdrawalRecord", data);
// 同步登录更改头像
export const imgdataApi = (data) => request("auth/authorization", data);
// 申请提现
export const TixianApi = (data) => request("distribution/userWithdrawalApply", data);
// 团队收益
export const TeamearningsApi = (data) => request("distribution/userTeamIncome", data);
// 广告参数
export const AdvertisingApi = (data) => request("putin/monitor", data);
// 充值状态
export const RechargestatusApi = (data) => request("pay/push_order", data);
//查询订单状态
export const cheackOrderStatus = (data) => request("pay/order_query", data)
// 书库列表
export const GetChartRanks = (data) => request("chart/ranks",data)
// 长篇阅读章节
export const LongHandApi = (data) => request("chapter/read", data)
//长篇阅读详情
export const LongDetailApi = (params) => request("book/detail", params)
const page_size = 10
// 书籍
export const Books = {
	//长篇阅读
		LongHand(book_id,passphrases) {
			return LongHandApi({
				data:{
					book_id,
					passphrases
				},
				method: 'POST',
			})
		},
	
	//长篇阅读详情
		LongDetai(data, showLoading = true) {
			return LongDetailApi({
				data,
				method: 'POST',
				showLoading,
			})
		},
	// 书库
		GetChartRanksApi(data){
			return GetChartRanks({
				data,
				showLoading: false
			})
		},
	//订单状态
	orderStatus(order_id) {
		return cheackOrderStatus({
			data: {
				order_id
			},

			method: 'POST',
			showLoading: false
		})
	},
	//首页
	HomeList() {
		return GetHomeListApi()
	},
	//阅读历史
	ReadHistoy(page) {
		return ReadHistoyApi({
			data: {
				page,
				page_size
			},
		})
	},
	//删除阅读历史
	DelReadHistoy(book_id) {
		return DelHistoryApi({
			data: {
				book_id
			},
			method: 'POST',
			showLoading: false
		})
	},
	//书架列表
	BookCase(page) {
		return BookcaseApi({
			data: {
				page,
				page_size
			},
			method: 'POST',

		})
	},
	//删除书架
	DelBookCase(book_id) {
		return delbooksApi({
			data: {
				book_id
			},
			method: 'POST',
			showLoading: false
		})
	},
	//搜索
	Search(search_keywords, page) {
		return SearchApi({
			data: {
				search_keywords,
				page,
				page_size,
			},
			showLoading: false
		})
	},
	//猜你喜欢
	Xiangsi(book_id, category_id) {
		return XiangSilApi({
			data: {
				book_id,
				category_id
			},
			showLoading: false
		})
	},
	//加入书架
	Addbooks(book_id) {
		return AddbooksApi({
			data: {
				book_id
			},
			method: 'POST',
			showLoading: false
		})
	},
	// 保存阅读记录
	SaveHistory(data) {
		return SaveHistoryApi({
			data,
			method: 'POST',
			showLoading: false
		})
	},
	// 书籍详情
	detail(id) {
		return IntroductionApi({
			data: {
				id
			},
			method: 'POST',
		})	
	},
	//分享口令
	async sharemoney(book_id) {
		let res = await SharecommandApi({
			data: {
				book_id
			},
			method: 'POST',
			showLoading: false
		})
		let book_password = (res.data.book_password).toString()
		uni.setClipboardData({
			data: `【请在抖音搜索“${app_name}”后搜索口令${book_password}，开始阅读吧】`,
			showToast: false,
			success: () => {
				uni.showToast({
					title: "【口令已复制，赶紧去抖音分享赚钱吧】",
					icon: 'none'
				})
			},
		});
	},
	//广告参数
	Advertising(data) {
		return AdvertisingApi({
			data,
			method: 'POST',
		})
	},
}
// 用户
export const Users = {
	//用户信息
	Userinfo() {
		return UserApi()
	},
	//充值金额配置
	Memberlist(data) {
		return MemberApi({
			data,
			showLoading: false
		})
	},
	//充值记录
	RechargeRecord(page) {
		return RechargeRecordApi({
			data: {
				page,
				page_size
			},
		})
	},
	// 充值
	Recharge(data) {
		return RechargeApi({
			data,
			method: 'POST',
		})
	},
	// 充值状态
	Rechargestatus(out_trade_no, status) {
		return RechargestatusApi({
			data: {
				out_trade_no,
				status
			},
			method: 'POST',
			showLoading: false
		})
	},
	//同步头像
	imgdata(nickname, user_image_url) {
		return imgdataApi({
			data: {
				nickname,
				sex: 0,
				user_image_url,
			},
			method: 'POST',
			showLoading: false
		})
	}
}
// 登录
export const Login = {
	// 登录
	async login(data) {
		let res = await LoginApi({
			data,
			method: 'POST',
		})
		if (res.status_code == 200) {
			uni.setStorageSync('token', res.data.access_token)
			const today = new Date().toLocaleDateString()
			uni.setStorageSync('today', today)
		}
	},
	// 刷新token
	shuatoken() {
		return TokenShuaApi({
			method: 'POST',
			showLoading: false
		})
	}
}
// 收益
export const Earnings = {
	//邀请码
	Code(invite_code) {
		return CodeApi({
			data: {
				invite_code,
			},
			method: 'POST',
		})
	},
	//今日收益
	Today(page) {
		return TodayearningsApi({
			data: {
				page,
				page_size: 15,
			},
		})
	},
	//历史收益
	History(date, page) {
		return HistoryearningsApi({
			data: {
				date,
				page,
				page_size: 15,
			},
			method: 'POST',
		})
	},
	//提现记录
	TiXian(date, page) {
		return TixianjiluApi({
			data: {
				date,
				page,
				page_size: 15,
			},
			method: 'POST',
		})
	},
	//团队收益
	Team(date, page) {
		return TeamearningsApi({
			data: {
				date,
				page,
				page_size: 15,
			},
			method: 'POST',
			showLoading: false
		})
	},
	//账户
	UserBalance() {
		return UserBalanceApi({
			showLoading: false
		})
	},
	//申请提现
	TX(data) {
		return TixianApi({
			data,
			method: 'POST',
		})
	}
}